#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int T,n,m,L,V,ans,che,cnt,v[maxn],a[maxn],k[maxn];
double p[maxn],d[maxn];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T--){
        ans=0,cnt=0,che=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++)cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++){
                cin>>p[i];
                k[i]=0;
        }
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(v[i]>V){
                    if(d[i]<=p[m]){
                        ans++;
                        che=1;
                    }
                }
            }
            if(a[i]>0){
                if(v[i]>V){
                    if(d[i]<=p[m]){
                        ans++;
                        che=1;
                    }
                }
                else {
                    double e=(double)(d[i]+(double)((long long)((V*V)-(v[i]*v[i]))/(2*a[i])));
                    if(e<p[m]){
                        ans++;
                        che=1;
                    }
                }
            }
            if(a[i]<0){
                if(v[i]>V){
                    double e=(double)(d[i]+(double)((double)((long long)(V*V)-(v[i]*v[i]))/(double)(2*a[i])));
                    int pe=lower_bound(p,p+m+1,d[i])-p;
                    if(p[pe]<e){
                        ans++;
                        bool fal=0;
                        for(int i=pe;i<=m;i++){
                            if(p[i]>=e)break;
                            if(k[i]){
                                fal=1;
                                break;
                            }
                        }
                        if(fal==0){
                            cnt++;
                            k[pe]=1;
                        }
                    }
                }
            }
        }
        if(che==1&&k[m]==1)che=0;
        cout<<ans<<" "<<m-cnt-che<<endl;
    }
    return 0;
}
